﻿using BCEntity.Sim.Company.Department;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace BCData.Sim.Company.Department
{
    /// <summary>
    /// 企业部门数据库访问
    /// </summary>
    public interface IDepartmentData
    {
        /// <summary>
        /// 新增部门
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>
        Task<DepartmentEntity> InsertAsync(DepartmentEntity department);

        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>
        Task<DepartmentEntity> UpdateAsync(DepartmentEntity department);

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        Task<bool> DeleteAsync(int id);

        /// <summary>
        /// 通过部门名称检查部门是否存在
        /// </summary>
        /// <param name="companyId">分公司Id</param>
        /// <param name="departmentName">部门名称</param>
        /// <returns></returns>
        Task<DepartmentEntity> CheckDepartmentName(int companyId, string departmentName);

        /// <summary>
        /// 通过ID查询
        /// </summary>
        /// <param name="departmentId"></param>
        /// <returns></returns>
        Task<DepartmentEntity> GetById(int departmentId);

        /// <summary>
        /// 查询负责人的部门信息
        /// </summary>
        /// <param name="principalAdminId">部门负责人id</param>
        /// <returns></returns>
        Task<DepartmentEntity> GetByPrincipalAdminId(long principalAdminId);

        /// <summary>
        /// 列表分页查询
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <param name="departmentName">部门名称</param>
		/// <param name="start">开始时间</param>
		/// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        Task<(IEnumerable<DepartmentEntity>, int dataCount)> Query(int companyId, string departmentName, DateTime? start, DateTime? end, string sortName, bool? ascending, int pageIndex, int pageSize);
        /// <summary>
        /// 查询子级部门
        /// </summary>
        /// <param name="departmentId">部门Id</param>
        /// <param name="companyId">公司Id</param>
        /// <returns></returns>
        Task<IEnumerable<DepartmentEntity>> QueryChildren(int departmentId, int companyId);
        /// <summary>
        /// 获取子级部门
        /// </summary>
        /// <param name="departmentId">部门Id</param>
        /// <returns></returns>
        Task<IEnumerable<DepartmentEntity>> QueryChildren(int departmentId);
        /// <summary>
        /// 获取跟部门列表
        /// </summary>
        /// <param name="companyId">公司配置Id</param>
        /// <returns></returns>
        Task<IEnumerable<DepartmentEntity>> QueryRootDepartment(int companyId);
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        Task<IEnumerable<DepartmentEntity>> GetAll(int companyId);

        /// <summary>
        /// 获取部门员工列表
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <param name="departmentId">部门Id</param>
        /// <returns></returns>

        Task<IEnumerable<DepartmentPrincipalEntity>> GetStaffList(int companyId, int? departmentId);

        /// <summary>
        /// 检查员工是不是部门负责人
        /// </summary>
        /// <param name="principalAdminId"></param>
        /// <returns></returns>
        Task<bool> CheckPrincipal(long principalAdminId);

        /// <summary>
        /// 通过部门id检查
        /// </summary>
        /// <param name="departmentId"></param>
        /// <returns></returns>
        Task<bool> CheckDepartment(int departmentId);

        /// <summary>
        /// 更新部门负责人
        /// </summary>
        /// <param name="companyId">公司id</param>
        /// <param name="departmentId">部门Id</param>
        /// <param name="adminId">员工Id</param>
        /// <param name="adminFullName">员工姓名</param>
        /// <returns></returns>
        Task<bool> UpdateDepartmentPrincipal(int companyId, int departmentId, long adminId, string adminFullName);
        /// <summary>
        /// 移除部门负责人信息
        /// </summary>
        /// <param name="companyId">公司id</param>
        /// <param name="departmentId">部门Id</param>
        /// <returns></returns>
        Task<DepartmentEntity> RemovePrincipalInfo(int companyId, int departmentId);

        /// <summary>
        /// 获取部门及子部门信息
        /// </summary>
        /// <param name="departmentId">部门Id</param>
        /// <param name="departmentExtendEntityList">部门信息列表</param>
        /// <returns></returns>
        Task<IEnumerable<DepartmentEntity>> GetDepartmentAndChildren(int departmentId, List<DepartmentEntity> departmentExtendEntityList);
        /// <summary>
        /// 更新员工数量
        /// </summary>
        /// <param name="departmentId">部门Id</param>
        /// <returns></returns>
        Task<bool> UpdateStaffCountAsync(int departmentId);
    }
}
